const ble = require("./utils/bluetooth");
const util = require("./utils/util")

App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    this.globalData.logs = logs

    const userinfo = wx.getStorageSync('userinfo') || {
      current_permission : 0
    }

    console.log("userinfo", userinfo)
    this.globalData.userInfo = userinfo

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  onHide(){
      ble.closeFromAirtu();
  },

  writeLog(info) {
    const information = {
      t : util.formatTime(new Date()),
      info : info
    }

    this.globalData.logs.unshift(information)
    if (this.globalData.logs.length > 50) {
      this.globalData.logs = this.globalData.logs.slice(0, 50);
    }
    console.log(this.globalData.logs)
    wx.setStorageSync('logs', this.globalData.logs)
  },
  globalData: {
    permission:{
      level_1 : "t123456",
      level_2 : "a123456",
      admin : "tas2518"
    },
    logs : [],
    userInfo: {
      current_permission : 0
    },
    battery : {
      full : "",
      design : "",
      bnums : "",
      resnse : "",
      shouming : "",
      fangdian_total : "",
      model : ""
    }
  }
})
